package com.frxuexi.park2210.notice

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.frxuexi.lib_base.mvvm.BaseActivity
import com.frxuexi.park2210.R
import com.frxuexi.park2210.databinding.ActivityNoticeBinding
import com.google.gson.Gson
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

@Route(path = "/app/NoticeActivity")
@AndroidEntryPoint
class NoticeActivity : BaseActivity<ActivityNoticeBinding,NoticeViewModel>(){
    val noticeAdapter by lazy { NoticeAdapter() }
    override fun initData() {

    }

    override fun initView() {
        binding.rvNotice.apply {
            adapter=noticeAdapter
            layoutManager=LinearLayoutManager(this@NoticeActivity)
        }


        binding.headerNotice.apply {
            headerBack.setOnClickListener {
                finish()
            }
            headerTitle.setText("公告管理")
            headerAdd.visibility=View.VISIBLE
            headerAdd.setOnClickListener {
                ARouter.getInstance().build("/app/NoticeAddActivity").navigation()
            }
        }

    }

    override fun onResume() {
        super.onResume()
        lifecycleScope.launch {
            vm.getNotice().collect{
                noticeAdapter.submitData(it)
            }
        }
    }

}